// JavaScript Document

//
function comment_register(form){
	if(pjs_ws){
		pjs_ws.postFormHandler = function(r){
			comment_load($E(r.f).target.value,$E(r.f).form.value,1);
		};
	}
	//
	comment_load(form.target.value,form.form.value,1);
}
//
function comment_load(target,type,page){
	xcb("ws/comment","ws_comment_load",[target,type,page]);
}
function comment_load_cb(r){
	$E("comments-listcomment").style.display = "none";
	$E("comments-listcomment").innerHTML = "";
	for(var i=0; i<r.items.length; i++){
		var li = document.createElement("LI");
		var name = document.createElement("SPAN");
		var time = document.createElement("SPAN");
		var cont = document.createElement("P");
		name.className = "name";
		time.className = "time";
		cont.className = "cont";
		name.innerHTML = r.items[i].author;
		time.innerHTML = r.items[i].date_added;
		cont.innerHTML = r.items[i].content.replace('\r\n',"<br>").replace('\n',"<br>").replace('\r',"<br>");
		li.appendChild(name);
		li.appendChild(time);
		li.appendChild(cont);
		$E("comments-listcomment").appendChild(li);
	}
	$E("comments-listcomment").style.display = "";
}
//
function comment_add(form){
	if(PJS.validator.checkFormValid(form)==false){
		return false;
	}
	//pjs_ws.postForm(form,'postform');
	xcb("ws/comment","ws_comment_add",[xcgfm(form.getAttribute("id")),form.getAttribute("id")]);
	return false;
}
function comment_add_cb(r){
	if(r.status==1){
		alert("OK");
		if(r.f && $E(r.f)){
			$E(r.f).reset();
		}
		comment_load($E(r.f).target.value,$E(r.f).form.value,1);
	} else {
		alert("Error");
	}
}